package com.wmuj.controller;

import com.wmuj.annotation.LogOperation;
import com.wmuj.pojo.*;
import com.wmuj.service.ClazzStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** 学员管理 */
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

  @Autowired private ClazzStudentService clazzStudentService;

  /** 学院列表查询 条件查询参数 */
  @GetMapping
  public Result queryStudentsList(StudentQueryParam studentQueryParam) {
    log.info("分页查询，参数：{}", studentQueryParam);
    PageResult<Student> pageResult = clazzStudentService.queryStudentsList(studentQueryParam);
    return Result.success(pageResult);
  }

  /** 删除学员 路径参数 参数为数组 ids */
  @LogOperation

  @DeleteMapping("/{ids}")
  public Result deleteStuIds(@PathVariable Integer[] ids) {
    log.info("删除学员，参数：{}", ids);
    clazzStudentService.deleteStuIds(ids);
    return Result.success();
  }

  /** 添加学员 */
  @LogOperation

  @PostMapping
  public Result addInfo(@RequestBody Student student) {
    log.info("添加学员，参数：{}", student);
    clazzStudentService.addInfo(student);
    return Result.success();
  }

  /** 根据id查询 */
  @GetMapping("/{id}")
  public Result findById(@PathVariable Integer id) {
    log.info("根据id查询，参数：{}", id);
    Student student = clazzStudentService.findById(id);
    return Result.success(student);
  }

  /** 修改学员 */
  @LogOperation

  @PutMapping
  public Result update(@RequestBody Student student) {
    log.info("修改学员，参数：{}", student);
    clazzStudentService.update(student);
    return Result.success();
  }

  /** 学员违纪处理 /violation/{id}/{score} */
  @LogOperation

  @PutMapping("/violation/{id}/{score}")
  public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
    log.info("违纪处理，参数：{}", id, score);
    clazzStudentService.violation(id, score);
    return Result.success();
  }
}
